//
//  ProductArrowCell.m
//  
//
//  Created by Abner on 16/4/28.
//
//

#import "ProductArrowCell.h"
#import "AddProduct.h"

@interface ProductArrowCell ()
{
    UIView *_topLine; //cell最上面的线，UI要求的，只有indexPath.row == 0时显示；
}
@end

@implementation ProductArrowCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _topLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
        _topLine.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        _topLine.alpha = 0.5;
        [self.contentView addSubview:_topLine];
        
        self.leftLb = [[UILabel alloc]init];
        [self.contentView addSubview:self.leftLb];
        self.leftLb.font = KAddLeftLbFont;
        self.leftLb.textColor = KAddLeftLbColor;
        self.leftLb.frame = CGRectMake(10, 0, 80, 44);

        self.categoryTf = [[UITextField alloc]init];
        [self.contentView addSubview:self.categoryTf];
        self.categoryTf.textColor = KAddLeftLbColor;
        self.categoryTf.font = KAddLeftLbFont;
        self.categoryTf.frame = CGRectMake(90, 0, ScreenWidth-130, 44);
        self.categoryTf.userInteractionEnabled = NO;
        self.categoryTf.placeholder = @"请选择商品分类";
        
        self.detaileLb = [[UILabel alloc]init];
        [self.contentView addSubview:self.detaileLb];
        self.detaileLb.font = KAddLeftLbFont;
        self.detaileLb.frame = CGRectMake(90, 14.5, ScreenWidth-115, 15);
        self.detaileLb.textAlignment = NSTextAlignmentRight;
        
        
        self.arrowBt = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.arrowBt];
        [self.arrowBt setImage:[UIImage imageNamed:@"arrow_icon"] forState:UIControlStateNormal];//7*12
        [self.arrowBt setImage:[UIImage imageNamed:@"arrow_icon"] forState:UIControlStateHighlighted];
        [self.arrowBt setImageEdgeInsets:UIEdgeInsetsMake(16, 123, 16, 10)];
        [self.arrowBt addTarget:self action:@selector(arrowBtClicked) forControlEvents:UIControlEventTouchUpInside];
        self.arrowBt.frame = CGRectMake(ScreenWidth-140, 0, 140, 44);

        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 44, ScreenWidth, 1)];
        line.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        line.alpha = 0.5;
        [self.contentView addSubview:line];
        
    }
    return self;
}

-(void)setupProductArrowCell:(NSString *)leftStr aLCProduct:(AddProduct *)aLCProduct andRow:(NSInteger)row
{
    self.leftLb.text = leftStr;
    if ([leftStr isEqualToString:@"商品图文描述"]) {
        self.leftLb.frame = CGRectMake(10, 0, 100, 44);
    }else{
        self.leftLb.frame = CGRectMake(10, 0, 80, 44);
    }

    if ([leftStr isEqualToString:@"商品分类"]) {
        self.categoryTf.hidden = NO;
    }else{
        self.categoryTf.hidden = YES;
    }
    if ([leftStr isEqualToString:@"商品简介"] || [leftStr isEqualToString:@"商品图文描述"]) {
        self.detaileLb.hidden = NO;
        self.detaileLb.text = @"未添加";
        self.detaileLb.textColor = KPlaceholderColor;
    }else{
        self.detaileLb.hidden = YES;
    }
    
    if (row == 0) {
        _topLine.hidden = NO;
    }else{
        _topLine.hidden = YES;
    }

}
//arrowBtClicked点击事件
-(void)arrowBtClicked
{
    if (self.arrowBtClickedBlock) {
        self.arrowBtClickedBlock(self);
    }
}


+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *indetifier = @"ProductArrowCellIdentifier";
    ProductArrowCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifier];
    if (!cell) {
        cell = [[ProductArrowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
    }
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
